<?php
	
	/**
	 * Verifies bootstrapper execution to ensure file
	 * necessities, and disabling direct access
	 */
	defined('ENGINE') or exit;
	
	/**
	 * Print a document error (startup) and halts script execution
	 *
	 * @param 	string 			The message to show
	 * @return	void			No value is returned
	 */
	function engine_doc_error($e)
	{
		static $called;
		global $engine;
		
		if(!is_null($called))
		{
			return;
		}
		
		$called		= true;
		$buffer		= ob_get_clean();
		$exception	= ($e instanceof Exception);
		$message	= ($exception ? $e->getMessage() : (string) $e);
		$errors		= Engine::globals('errors');
		$submessage	= 'If you are a visitor to this site, please notify the site administrator of this error so it may be fixed as soon as possible';
		
		if($e instanceof Engine_SQL_Exception)
		{
			$queries = $engine->db->get_queries();
			
			$message	= '<strong>An error occured while querying the database.</strong>';
			$submessage	= '<strong>[' . constant(get_class($engine->db) . '::DRIVER_NAME') . '] Error Code #' . $e->getCode() . ':</strong> ' . (str_replace(array('\r', '\n'), '', $e->getMessage())) . '<br />';
			$submessage .= '<code>' . ($queries[ count($queries) - 1 ]) . '</code>';
		}
		if($e instanceof Engine_Template_Exception)
		{
			$message = '<strong>A templating error has occured:</strong><br />' . $message;
		}
		else if(empty($message))
		{
			$message = 'Unknown error occured!';
		}
		else if(function_exists('utf8_encode'))
		{
			$message = utf8_encode($message);
		}
		
		header('Content-Type: text/html');
		
		echo(
			'<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . 
			'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . PHP_EOL . 
			'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">' . PHP_EOL . 
			'<head>' . PHP_EOL . 
			'<title>Fatal Engine Error</title>' . PHP_EOL . 
			'<style type="text/css">' . PHP_EOL . 
			'<!--' . PHP_EOL . 
			'body {' . PHP_EOL . 
			'	background: #ffffff;' . PHP_EOL . 
			'	margin: 0;' . PHP_EOL . 
			'	padding: 10px;' . PHP_EOL . 
			'	font: 14px Calibri, Tahoma, sans-serif;' . PHP_EOL . 
			'	line-height: 1;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'.clearfix {' . PHP_EOL . 
			'	clear: both;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'#banner {' . PHP_EOL . 
			'	background-color: #0f0f0f;' . PHP_EOL . 
			'	background:-webkit-gradient(linear, left top, left bottom, from(rgba(15,15,15,0.75)), to(rgba(15,15,15,0.95)) );' . PHP_EOL .
			'	background: -moz-linear-gradient(center top, rgba(15,15,15,0.75) 0%, rgba(15,15,15,0.95) 100%);' . PHP_EOL . 
			'	border: 1px solid #101010;' . PHP_EOL . 
			'	border-bottom: 1px solid #161616;' . PHP_EOL . 
			'	border-radius: 5px;' . PHP_EOL . 
			'	margin: 150px auto 7px;' . PHP_EOL . 
			'	width: 990px;' . PHP_EOL . 
			'	color: #ececec;	' . PHP_EOL . 
			'	/** Browser Specific CSS3 Styles **/' . PHP_EOL . 
			'	-webkit-border-radius: 5px;' . PHP_EOL . 
			'	-moz-border-radius: 5px;' . PHP_EOL . 
			'	-webkit-box-shadow: 0 0 15px #a5a5a5;' . PHP_EOL . 
			'	-moz-box-shadow: 0 0 15px #a5a5a5;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'#banner:hover {' . PHP_EOL . 
			'	-webkit-box-shadow: 0 0 15px #5f5f5f;' . PHP_EOL . 
			'	-moz-box-shadow: 0 0 15px #5f5f5f;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'#banner div#container {' . PHP_EOL . 
			'	border: 1px solid #474747;' . PHP_EOL . 
			'	border-top-color: #898989;' . PHP_EOL . 
			'	border-bottom: none;' . PHP_EOL . 
			'	border-radius: 5px;' . PHP_EOL . 
			'	padding: 20px 23px;' . PHP_EOL . 
			'	/** Browser Specific CSS3 Styles **/' . PHP_EOL . 
			'	-webkit-border-radius: 5px;' . PHP_EOL . 
			'	-moz-border-radius: 5px;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'#banner h1,' . PHP_EOL . 
			'#banner h2 {' . PHP_EOL . 
			'	margin: 0;' . PHP_EOL . 
			'	padding: 0 0 4px;' . PHP_EOL . 
			'	font-size: 14px;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'#banner h2 {' . PHP_EOL . 
			'	font-weight: normal;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'#banner span {' . PHP_EOL . 
			'	font-size: 12px;' . PHP_EOL . 
			'	color: #c0c0c0;' . PHP_EOL . 
			'	line-height: 20px;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'#banner #info {' . PHP_EOL . 
			'	float: right;' . PHP_EOL .
			'	text-align: right;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'#footer {' . PHP_EOL . 
			'	margin: 15px auto;' . PHP_EOL . 
			'	width: 970px;' . PHP_EOL . 
			'	font-size: 12px;' . PHP_EOL . 
			'	text-align: right;' . PHP_EOL .
			'	color: #909090;' . PHP_EOL . 
			'}' . PHP_EOL . 
			'// -->' . PHP_EOL . 
			'</style>	' . PHP_EOL . 
			'</head>' . PHP_EOL . 
			'<body>' . PHP_EOL . 
			'<div id="banner">' . PHP_EOL . 
			'<div id="container">' . PHP_EOL . 
			'<div id="info"><h2>' . nl2br($message) . '</h2>' . PHP_EOL . 
			'<span>' . nl2br($submessage) . '</span>' .  PHP_EOL . 
			'</div>' . PHP_EOL . 
			'<h1>Chase Engine</h1>' . PHP_EOL . 
			'<span>A Fatal System Error Has Occured</span>' . PHP_EOL . 
			'<div class="clearfix"></div>' . PHP_EOL . 
			'</div>' . PHP_EOL . 
			'</div>' . PHP_EOL . 
			'<div id="footer">' . PHP_EOL . 
			'This error was generated from Chase Engine version ' . Engine::VERSION_STRING . ' on ' . ENGINE_SERVER_VERSION . ' using PHP Version ' . ENGINE_PHP_VERSION . PHP_EOL . 
			'</div>' . PHP_EOL . 
			'</body>' . PHP_EOL . 
			'</html>' . PHP_EOL 
		);
	}

?>